using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Zoo.DAL
{
    /// <summary>
    /// Controller class for ZooUsers
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class ZooUserController
    {
        // Preload our schema..
        ZooUser thisSchemaLoad = new ZooUser();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public ZooUserCollection FetchAll()
        {
            ZooUserCollection coll = new ZooUserCollection();
            Query qry = new Query(ZooUser.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public ZooUserCollection FetchByID(object UserID)
        {
            ZooUserCollection coll = new ZooUserCollection().Where("UserID", UserID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public ZooUserCollection FetchByQuery(Query qry)
        {
            ZooUserCollection coll = new ZooUserCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object UserID)
        {
            return (ZooUser.Delete(UserID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object UserID)
        {
            return (ZooUser.Destroy(UserID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string UserLanguage,string NickName,string EmailAddress,string Gender,string Seeking,int CountryID,int RegionID,DateTime BornDate,string City,string Description,DateTime RegistrationDate,DateTime LastLogin,bool Online,string Password,bool EmailOptin)
	    {
		    ZooUser item = new ZooUser();
		    
            item.UserLanguage = UserLanguage;
            
            item.NickName = NickName;
            
            item.EmailAddress = EmailAddress;
            
            item.Gender = Gender;
            
            item.Seeking = Seeking;
            
            item.CountryID = CountryID;
            
            item.RegionID = RegionID;
            
            item.BornDate = BornDate;
            
            item.City = City;
            
            item.Description = Description;
            
            item.RegistrationDate = RegistrationDate;
            
            item.LastLogin = LastLogin;
            
            item.Online = Online;
            
            item.Password = Password;
            
            item.EmailOptin = EmailOptin;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int UserID,string UserLanguage,string NickName,string EmailAddress,string Gender,string Seeking,int CountryID,int RegionID,DateTime BornDate,string City,string Description,DateTime RegistrationDate,DateTime LastLogin,bool Online,string Password,bool EmailOptin)
	    {
		    ZooUser item = new ZooUser();
		    
				item.UserID = UserID;
				
				item.UserLanguage = UserLanguage;
				
				item.NickName = NickName;
				
				item.EmailAddress = EmailAddress;
				
				item.Gender = Gender;
				
				item.Seeking = Seeking;
				
				item.CountryID = CountryID;
				
				item.RegionID = RegionID;
				
				item.BornDate = BornDate;
				
				item.City = City;
				
				item.Description = Description;
				
				item.RegistrationDate = RegistrationDate;
				
				item.LastLogin = LastLogin;
				
				item.Online = Online;
				
				item.Password = Password;
				
				item.EmailOptin = EmailOptin;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

